<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magento.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magento.com for more information.
 *
 * @category    design
 * @package     base_default
 * @copyright   Copyright (c) 2006-2015 X.commerce, Inc. (http://www.magento.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<?php
/**
 * Product list template
 *
 * @see Mage_Catalog_Block_Product_List
 */
?>
<?php
$_productCollection=$this->getLoadedProductCollection();

//new
$_newProductCollection = Mage::getModel('catalog/product')->getCollection()
            ->setPage(1,4)
            ->setOrder("entity_id")
            ->addAttributeToSelect('*');
Mage::getSingleton('catalog/product_status')->addSaleableFilterToCollection($this->_newProductCollection);
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($_newProductCollection);
Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($_newProductCollection);
$_newProductCollection->getSelect()->group('e.entity_id');

$_helper = $this->helper('catalog/output');
$zgbHelper = Mage::helper('zgb');
?>
<?php if(!$_productCollection->count()): ?>
<p class="note-msg"><?php echo $this->__('There are no products matching the selection.') ?></p>
<?php else: ?>
<div class="category-products">
    <?php echo $this->getToolbarHtml() ?>
    

    <?php
        $_rootCategoryId = Mage::app()->getStore()->getRootCategoryId();
        $_allCategoryId = Mage::getModel("catalog/category")->load($_rootCategoryId)
                            ->getChildren();
        $_currentCategoryId = Mage::app()->getRequest()->getParam("id");
        $_currentOrder = Mage::app()->getRequest()->getParam("order");
        $_currentBrand = Mage::app()->getRequest()->getParam("brand");
        $_brand = $this->getRequest()->getParam('brand');
        $_cat = $this->getRequest()->getParam('cat');
        $_currentPageNum = Mage::getBlockSingleton('page/html_pager')->getCurrentPage();
        $_newIds = array();
    ?>
    <?php if(!$$_brand && !$_cat && $_currentCategoryId == $_allCategoryId && !($_currentOrder.$_currentBrand) && $_currentPageNum === 1): ?>
        <ul class="list-grid">
        <?php foreach($_newProductCollection as $_product):?>
            <?php $_newIds[] = $_product->getId(); ?>
            
                <li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
                    <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image">
                        <img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(210); ?>" width="210" height="210" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
                        <?php if($zgbHelper->hasTag($_product)): ?>
                            <div class="product-sale-tag">
                                <img src="<?php echo $zgbHelper->getSaleTagUrl($_product, $this->getSkinUrl('images')); ?>" alt="" />
                            </div>
                        <?php endif; ?>
                    </a>

                    <?php 
                    $proid = $_product->getId();
                    $pro = Mage::getModel('catalog/product')->load($proid);
                    ?>
                    <h2 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>">
                    <?php if($pro->getpromotion()):?>
                        <span class="promo-msg"><?php echo $pro->getpromotion();?></span>
                    <?php endif;?>
                    <?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></a></h2>

                    <?php 
                        $tags = Mage::helper('zgb')->getProductInfoTags($_product);
                        if($tags):
                        foreach($tags as $i => $tag):
                    ?>
                        <span class="product-info-tags <?php if($i==0) echo 'product-info-tags-first' ?>" ><?php echo $tag; ?></span>
                    <?php endforeach; ?>
                    <?php endif; ?>

                    <?php echo $this->getPriceHtml($_product, true) ?>
                    
                    <div class="addToCart" data-action="<?php echo $this->getUrl('checkout/cart/addAjax',array('product'=>$_product->getId())); ?>">
                        <span class="fa nfa-minus num-down" id="num-down"></span>
                        <span class="qty-span"><input type="text" name="qty" class="pnum" id="qty"/></span>
                        <span class="fa nfa-plus num-up" id="num-up"></span>
                        <button class="add-to-cart-button cart-icon">加入购物车</button>
                    </div>

                </li>
            
        <?php endforeach;?>
        </ul>
    <?php endif;?>

    <?php $_collectionSize = $_productCollection->count() ?>
    <?php $_columnCount = 4; ?>
    <?php $i=0; foreach ($_productCollection as $_product): ?>
        <?php if(in_array($_product->getId(),$_newIds)) continue;?>
        <?php if ($i++%$_columnCount==0): ?>
        <ul class="list-grid">
        <?php endif ?>
            <li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
                <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image">
                    <img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(210); ?>" width="210" height="210" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
                    <?php if($zgbHelper->hasTag($_product)): ?>
                        <div class="product-sale-tag">
                            <img src="<?php echo $zgbHelper->getSaleTagUrl($_product, $this->getSkinUrl('images')); ?>" alt="" />
                        </div>
                    <?php endif; ?>
                </a>

                <?php 
                $proid = $_product->getId();
                $pro = Mage::getModel('catalog/product')->load($proid);
                ?>
                <h2 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>">
                <?php if($pro->getpromo_msg()):?>
                    <span class="promo-msg"><?php echo $pro->getpromo_msg();?></span>
                <?php endif;?>
                <?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></a>
                </h2>
                
                <div class="productCuxiao">
                    <?php if($_product->getPromotion()):?>
                    <span><?php echo $_product->getPromotion()?></span>
                    <?php endif;?>
                </div>
                
                <?php 
                    $tags = Mage::helper('zgb')->getProductInfoTags($_product);
                    if($tags):
                    foreach($tags as $i => $tag):
                ?>
                    <span class="product-info-tags <?php if($i==0) echo 'product-info-tags-first' ?>" ><?php echo $tag; ?></span>
                <?php endforeach; ?>
                <?php endif; ?>

                <?php echo $this->getPriceHtml($_product, true) ?>

                <div class="addToCart" data-action="<?php echo $this->getUrl('checkout/cart/addAjax',array('product'=>$_product->getId())); ?>">
                   <!-- <span class="fa nfa-minus num-down">123123123</span>-->
                    <span class="fa nfa-minus num-down" id="num-down"></span>
                    <span class="qty-span"><input type="text" name="qty" class="pnum" id="qty"/></span>
                    <span class="fa nfa-plus num-up" id="num-up"></span>
                    <button class="add-to-cart-button cart-icon">加入购物车</button>
                </div>

            </li>
        <?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
        </ul>
        <?php endif ?>
        <?php endforeach ?>
        <script type="text/javascript">decorateGeneric($$('ul.products-grid'), ['odd','even','first','last'])</script>


    <div class="toolbar-bottom">
        <?php echo $this->getToolbarHtml() ?>
    </div>
</div>
<?php endif; ?>
